<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view contentType="text/html" locale="en">
	<h:head />
	<h:body>
		<div class="wrap container">
			<ui:include src="/views/blocks/header.xhtml" />
			<f:metadata>
				<f:event listener="#{todoBean.init()}" type="preRenderView"/>
			</f:metadata>
			<h:form id="scheduleForm">
			<p:growl id="messages" showDetail="true" />
				<p:schedule value="#{todoBean.eventModel}" id="calendar"
					widgetVar="myschedule" timeZone="GMT+3">
					<p:ajax event="dateSelect" listener="#{todoBean.onDateSelect}"
						update=":dialogForm:eventDetails"
						oncomplete="PF('eventDialog').show();" />
					<p:ajax event="eventSelect" listener="#{todoBean.onEventSelect}"
						update=":dialogForm:eventDetails"
						oncomplete="PF('eventDialog').show();" />
					<p:ajax event="eventMove" listener="#{todoBean.onEventMove}"
						update="messages" />
					<p:ajax event="eventResize" listener="#{todoBean.onEventResize}"
						update="messages" />
				</p:schedule>
			</h:form>
			<h:form id="dialogForm">
				<p:dialog widgetVar="eventDialog" header="Event Details"
					showEffect="clip" hideEffect="clip">
					<h:panelGrid id="eventDetails" columns="2">
						<p:message for="to" />
						<p:message for="title" />

						<h:outputLabel for="title" value="Title:" />
						<p:inputText id="title" value="#{todoBean.event.title}"
							required="true" />

						<h:outputLabel for="from" value="From:" />
						<p:calendar id="from" value="#{todoBean.event.startDate}"
							pattern="dd/MM/yyyy HH:mm" timeZone="GMT+3">
							<f:validator binding="#{fromDateValidator}" />
						</p:calendar>

						<h:outputLabel for="to" value="To:" />
						<p:calendar id="to" value="#{todoBean.event.endDate}"
							pattern="dd/MM/yyyy HH:mm" timeZone="GMT+3">
							<f:attribute name="from" value="#{todoBean.event.startDate}" />
							<f:validator binding="#{toDateValidator}" />
						</p:calendar>

						<h:outputLabel for="actual" value="Actual end date:" />
						<p:calendar id="actual" value="#{todoBean.event.actualEndDate}"
							pattern="dd/MM/yyyy HH:mm" timeZone="GMT+3">
							<f:attribute name="from" value="#{todoBean.event.startDate}" />
							<f:validator binding="#{toDateValidator}" />
						</p:calendar>

						<h:outputLabel for="comment" value="Comment:" />
						<p:inputText id="comment" value="#{todoBean.event.comment}" />

						<h:outputLabel for="allDay" value="All Day:" />
						<h:selectBooleanCheckbox id="allDay"
							value="#{todoBean.event.allDay}" />

					</h:panelGrid>

					<h:panelGrid id="buttons" columns="3">
						<p:commandButton type="reset" value="Reset" />
						<p:commandButton id="addButton" value="Save" 
							validateClient="true"
							actionListener="#{todoBean.addEvent}"
							update=":scheduleForm:messages"
							oncomplete="PF('myschedule').update();PF('eventDialog').hide();" />
						<p:commandButton id="deleteButton" value="Delete"
							actionListener="#{todoBean.deleteEvent}"
							update=":scheduleForm:calendar :scheduleForm:messages" 
							immediate="true"/>
					</h:panelGrid>

				</p:dialog>
			</h:form>
		</div>
	</h:body>
</f:view>
</html>